﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNet.Identity;
using Sharp.DataTransferObject;


namespace Sharp.Portal.Owin
{
    [Serializable]
    public class SharpUser : UserDTO, Microsoft.AspNet.Identity.IUser<int>
    {
        public SharpUser()
        {
        }
        public SharpUser(UserDTO dto)
        {
            this.Id = dto.Id;
            this.Face = dto.Face;
            this.UserName = dto.UserName;
            this.Password = dto.Password;
            this.Permissions = dto.Permissions;
            this.RoleNames = dto.Roles.Select(x => x.Name).ToArray();
        }

        public string[] RoleNames { get; set; }


        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(SharpUserManager manager)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
            return userIdentity;
        }
    }
}